From 70cfb8f7762b9e40341583009e49c2b728eea254 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Tue, 6 Jul 2021 19:56:03 +0200 Subject: [PATCH] [PATCH] seq_file: Disallow extremely large seq buffer allocations There is no reasonable need for a buffer larger than this, and it avoids int overflow pitfalls. Fixes: 058504edd026 ("fs/seq_file: fallback to vmalloc allocation") Reported-by: Qualys Security Advisory Suggested-by: Al Viro Signed-off-by: Eric Sandeen Gbp-Pq: Topic bugfix/all Gbp-Pq: Name seq_file-Disallow-extremely-large-seq-buffer-allocat.patch --- fs/seq_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index 03a369ccd28..472714716be 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -32,6 +32,9 @@ static void seq_set_overflow(struct seq_file *m) static void *seq_buf_alloc(unsigned long size) { + if (unlikely(size > MAX_RW_COUNT)) + return NULL; + return kvmalloc(size, GFP_KERNEL_ACCOUNT); } -- 2.30.2